<?php

include 'config.php';
include 'common.php';

if(isset($_COOKIE['token'])){
    header("Location: https://m.mxzhuawawa.com/");
}

if(is_weixin()) {
    if(!isset($_COOKIE['token'])) {
        $data = array(
            "appid" => $config['AppId'],
            "redirect_uri" => "https://m.mxzhuawawa.com/wx_callback.php",
            "response_type" => "code",
            "scope" => "snsapi_userinfo",
            "state" => "weixinCashCallback",
        );

        $url = "https://open.weixin.qq.com/connect/oauth2/authorize?".http_build_query($data)."#wechat_redirect";
        header("Location: {$url}");
    }
} else {
    if(!isset($_COOKIE['token'])) {
        header("Location: https://m.mxzhuawawa.com/login.html");
    }
}

